package com.hahaliu.hahaliu.controller.admin;

import com.hahaliu.hahaliu.common.context.CurrentUser;
import com.hahaliu.hahaliu.common.exception.BaseException;
import com.hahaliu.hahaliu.common.result.Result;
import com.hahaliu.hahaliu.pojo.vo.VideoInfoVO;
import com.hahaliu.hahaliu.service.video.VideoAuditService;
import com.hahaliu.hahaliu.service.video.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController("adminVideoController")
@RequestMapping("/admin/video")
@Api(tags = "管理端视频相关接口")
@Slf4j
public class VideoController {
	@Autowired
	private VideoAuditService videoAuditService;

	@Autowired
	private CurrentUser currentUser;

	@Autowired
	private VideoService videoService;

//	@GetMapping("/page")
//	@ApiOperation("分页查询")
//	public Result<IPage<VideoInfoVO>> page(@RequestParam("vstatus") Integer status,
//	                                 @RequestParam(value = "page", defaultValue = "1") Integer page,
//	                                 @RequestParam(value = "quantity", defaultValue = "10") Integer quantity) {
//
//		IPage<VideoInfoVO> videoInfoVOIPage = videoService.selectUserPage(status, page, quantity);
//
//		return Result.success(videoInfoVOIPage);
//	}

//	@PostMapping("/change/status")
//	@ApiOperation("改变视频状态")
//	public Result updateVideoStatus(@RequestParam("vid") Integer vid, @RequestParam("status") Integer status) {
//		videoService.updateVideoStatus(vid, status);
//
//		return Result.success();
//	}
	/**
	 * 审核 查询对应状态的视频数量
	 * @param status 状态 0待审核 1通过 2未通过
	 * @return 视频数量
	 */
	@GetMapping("/audit/total")
	@ApiOperation("查询对应状态的视频数量")
	public Result<Long> getTotal(@RequestParam("status") Integer status) {
		return Result.success(videoAuditService.getTotalByStatus(status));
	}

	/**
	 * 审核 分页查询对应状态视频
	 * @param status 状态 0待审核 1通过 2未通过
	 * @param page  当前页
	 * @param quantity  每页的数量
	 * @return 视频列表
	 */
	@GetMapping("/audit/page")
	@ApiOperation("分页查询对应状态视频")
	public Result<List<Map<String, Object>>> getVideos(@RequestParam("status") Integer status,
									@RequestParam(value = "page", defaultValue = "1") Integer page,
									@RequestParam(value = "quantity", defaultValue = "10") Integer quantity) {
		return Result.success(videoAuditService.getVideosByPage(status, page, quantity));
	}

	/**
	 * 审核 查询单个视频详情
	 * @param vid 视频id
	 * @return 视频信息
	 */
	@GetMapping("/audit/getone")
	@ApiOperation("查询单个视频详情")
	public Result<VideoInfoVO> getOneVideo(@RequestParam("vid") Integer vid) {
		if (!currentUser.isAdmin()) {
			throw new BaseException("您不是管理员，无权访问");
		}
		return Result.success(videoService.getVideoWithDataById(vid));
	}

}
